#include "theaterconst.h"

/* MovieTechnician */
void main() {
	int movieTime;
	int i;
	
	init();
	
	Acquire(movieLock);
	SetMonitor(movieState, 0, M_WAITING);
	Release(movieLock);
	while (1) {
		Acquire(mtLock);
		Wait(mtCV, mtLock);
		/* told by manager to start the movie */
		SetMonitor(movieState, 0, M_STARTED);
		Release(mtLock);
		Acquire(outputLock);
		prints("The MovieTechnician has started the movie.\n");
		Release(outputLock);
		movieTime = Rand(100) + 200;
		/* playing the movie */
		for(i  = 0; i < movieTime; i++) {
			Yield();
		}
		Acquire(outputLock);
		prints("The MovieTechnician has ended the movie.\n");
		Release(outputLock);
		Acquire(movieLock);
		/* movie's finished. broadcast all customers */
		Acquire(outputLock);
		prints("The MovieTechnician has told all customers to leave the theater room.\n");
		Release(outputLock);
		Broadcast(movieCV, movieLock);
		SetMonitor(movieState, 0, M_FINISHED);
		Release(movieLock);
	}
	
	Exit(0);
}